﻿using System;
using Lidgren.Network;

namespace Network
{
    /// <remarks>Copied from Eric Maupin's Tempest networking library</remarks>
    public class MessageEventArgs<T> : EventArgs
        where T : Message
    {
        public MessageEventArgs(NetworkPeer netowrPeer, NetConnection connection, T message)
        {
            if (netowrPeer == null)
                throw new ArgumentNullException(nameof(netowrPeer));
            if (connection == null)
                throw new ArgumentNullException(nameof(connection));
            NetworkPeer = netowrPeer;
            Connection = connection;
            Message = message;
        }
        public MessageEventArgs(NetworkPeer netowrPeer, T message)
        {
            if (netowrPeer == null)
                throw new ArgumentNullException(nameof(netowrPeer));
            NetworkPeer = netowrPeer;
            Message = message;
        }

        public MessageEventArgs(NetConnection connection, T message)
        {
            if (connection == null)
                throw new ArgumentNullException(nameof(connection));
            Message = message;
            Connection = connection;
        }

        /// <summary>
        /// 当前的连接
        /// </summary>
        public NetConnection Connection { get; private set; }

        /// <summary>
        /// Gets the NetClient or NetServer for the event.
        /// 目前发现这个并没有用到，可能是开源的一个坑。
        /// 目的可能是想得到当前的连接，但是放错了对象
        /// </summary>
        public NetworkPeer NetworkPeer { get; private set; }
        
        public T Message { get; private set; }
    }

    /// <summary>
    /// Holds event data for a MessageReceived event.
    /// </summary>
    /// <remarks>Copied from Eric Maupin's Tempest networking library</remarks>
    public class MessageEventArgs : EventArgs
    {
        /// <summary>
        /// Creates a new instance of <see cref="MessageReceivedEventArgs"/>.
        /// </summary>
        /// <param name="networkPeer">The parent NetClient or NetServer connection.</param>
        public MessageEventArgs(NetworkPeer networkPeer, NetConnection connection, Message message)
        {
            if (networkPeer == null)
                throw new ArgumentNullException(nameof(networkPeer));
            if (connection == null)
                throw new ArgumentNullException(nameof(connection));
            if (message == null)
                throw new ArgumentNullException(nameof(message));

            NetworkPeer = networkPeer;
            Message = message;
            Connection = connection;

        }
        public MessageEventArgs(NetworkPeer networkPeer,  Message message)
        {
            if (networkPeer == null)
                throw new ArgumentNullException(nameof(networkPeer));
            if (message == null)
                throw new ArgumentNullException(nameof(message));

            NetworkPeer = networkPeer;
            Message = message;
        }
        public MessageEventArgs(NetConnection connection, Message message)
        {
            if (connection == null)
                throw new ArgumentNullException(nameof(connection));

            if (message == null)
                throw new ArgumentNullException(nameof(message));

            Connection = connection;
            Message = message;
        }
        /// <summary>
        /// 当前的连接
        /// </summary>
        public NetConnection Connection { get; private set; }
        /// <summary>
        /// Gets the connection for the event.
        /// </summary>
        public NetworkPeer NetworkPeer { get; private set; }

        /// <summary>
        /// Gets the message received.
        /// </summary>
        public Message Message { get; private set; }
    }
}